/*
 * Copyright (c) 2016. For Intelligent Group.
 */
package com.intelligent.ispc.client.core.controller;

import com.intelligent.ispc.client.utils.ResourceMessages;
import com.intelligent.ispc.core.dto.UserDto;
import com.intelligent.ispc.core.service.SecurityService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by simon.liu on 2016/9/14.
 */
@Component
public class ChangePwdController {
    private final Logger logger = LoggerFactory.getLogger(ChangePwdController.class);
    @Autowired
    private SecurityService securityService;

    /**
     * Check the old password.
     *
     * @param oldPwd password.
     * @return true if equals.
     */
    public boolean isOldPwdOk(String oldPwd) {
        UserDto userDto = ResourceMessages.userMap.get("user");
        if (oldPwd.equals(userDto.getPassword())) {
            return true;
        }
        return false;
    }

    /**
     * Update user information.
     *
     * @param userDto user info
     */
    public void updateUserInfo(UserDto userDto) {
        securityService.updateUserPwdByUserDto(userDto);
    }
}
